<template>
	<view class="minh-bg">
		<fa-navbar title="盘点历史"></fa-navbar>
		<view class="fa-report-list p-2">
			<view class="fa-al-box py-m2 mb-1 bg-ff" v-for="(item, idx) in reportList" :key="idx" @click="toPage(item.Guid)">
				<view class="flex-between pb-min font24 px-m2 col-gray" style="align-items: center;border-bottom: 1px solid #ECECF0;">
					<text>盘点时间：{{ formatDate(item.CreateTime) }}</text>
				</view>
				<u-row gutter="0" class="px-m2 pt-m2">
					<u-col span="10" class="fa-al-title col-mark">
						<view class="flex-between font28">
							<text class="m-col m-col12 u-line-1">房产：{{ item.OrgName }}</text>
							<text class="m-col m-col12 pl-m1 u-line-1">盘点人：{{ item.UserName }}</text>
						</view>
						<view class="mt-m2 font24">报告生成时间：<text style="color: #2E73E5;">{{ formatDate(item.EndTime) }}</text></view>
					</u-col>
					<u-col span="2" class="text-right">
						<u-icon name="arrow-right" color="#999999"></u-icon>
					</u-col>
				</u-row>
			</view>
			<!-- 暂无数据 -->
			<view v-if="noData" class="text-center col-gray">没有数据</view>
		</view>
	</view>
</template>

<script>
	import faNavbar from '@/components/fa-navbar/fa-navbar.vue'
	import SOtime from '@/js_sdk/fl-SOtime/SOtime.js'
	export default {
		components: {
			faNavbar
		},
		data() {
			return {
				reportList: [],
				noData: false
			}
		},
		onLoad() {
			uni.showLoading({
				title: '加载中'
			})
			this.getUserCurrentDataFunc();
		},
		methods: {
			// 格式化时间戳转日期
			formatDate(date) {
				return SOtime.time3(date)
			},
			
			// 获取OrgGuids
			getUserCurrentDataFunc() {
				this.$api.getUserCurrentDataFunc({})
					.then(res => {
						if (res.code === 0) {
							this.getCheckHistoryList(res.data.DataFuncList);
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
						}
					})
					.catch(err => console.error(err))
			},
			
			// 获取历史报告列表
			getCheckHistoryList(data) {
				this.$api.getCheckHistoryList({OrgGuids: data})
					.then(res => {
						if (res.code === 0) {
							this.reportList = res.data;
							if (this.reportList.length == 0) {
								this.noData = true;
							}else {
								this.noData = false;
							}
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
						}
						uni.hideLoading();
					})
					.catch(err => console.error(err));
			},
			
			toPage(guid) {
				uni.redirectTo({
					url: `/pages/report/report?reportId=${guid}`
				});
			}
		}
	}
</script>

<style lang="scss">
	.fa-report-list {
		.fa-al-box {
			border-radius: 8rpx;
			box-shadow: 0px 8rpx 24rpx rgba($color: #3D4C62, $alpha: .12);
		}
		.u-cell {
			padding: 0;
			padding-top: 20rpx;
			line-height: 44rpx;
		}
	}
</style>
